#ifdef __cplusplus
extern "C"{
#endif
#ifndef __XS_DEF_H__
#define __XS_DEF_H__

#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <regex.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>	
#include <sys/types.h>
#include <sys/uio.h>    /* for surpporting struct iovec, writev and readv interface */
#include <sys/utsname.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>

#define TRUE   1
#define FALSE   (!TRUE)
#define NEWLINE  ("\r\n")

#ifndef offsetof
#define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif

#ifndef container_of
#ifdef WIN32
#define container_of(ptr, type, member)                \
            (type *)((char *)ptr - offsetof(type, member))
#else
#define container_of(ptr, type, member) ({            \
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
    (type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#endif
#define xs_entry(ptr, type, member) \
    container_of(ptr, type, member)


#define max(x, y) ({				\
    typeof(x) _max1 = (x);			\
    typeof(y) _max2 = (y);			\
    (void) (&_max1 == &_max2);		\
    _max1 > _max2 ? _max1 : _max2; })

#define min(x, y) ({				\
    typeof(x) _min1 = (x);			\
    typeof(y) _min2 = (y);			\
    (void) (&_min1 == &_min2);		\
    _min1 < _min2 ? _min1 : _min2; })


#define EXIT_OK             				EXIT_SUCCESS    /* 0 */
#define EXIT_ERROR                          EXIT_FAILURE    /* 1 */
#define TIME_OUT          				(-2)
#define NOT_IMPLEMENTED	  		(-3)
#define PARAMETER_ERROR   			(-4)
#define HARDWARE_ERROR	  		(-5)
#define MEMORY_ERROR	  			(-6)
#define QUEUE_IS_FULL     			(-7)
#define QUEUE_IS_EMPTY    			(-8)

extern int errno; 
#define xs_dump_error_str(errno)	xs_logd("%s", strerror(errno))

typedef struct timespec timespec_t; /* timespec defined in time.h */



#endif
#ifdef __cplusplus
}
#endif
